import { createVNode, render } from 'vue'
import ContextMenu from './ContextMenu.vue'

export interface ActionItem {
  action: (componentId: string) => void
  text: string
  shortcut: string
}

export default function createContextMenu(actions: ActionItem[], triggerClass = 'edit-wrapper') {
  const container = document.createElement('div')
  const options = {
    actions,
    triggerClass
  }

  const vm = createVNode(ContextMenu, options)
  render(vm, container)
  document.body.appendChild(container)

  // 返回用于销毁资源的函数
  return () => {
    render(null, container)
    document.body.removeChild(container)
  }
}
